package com.food.platformmsgmanagement.adapter.inbound;

import com.food.platformmsgmanagement.domain.Comment;
import com.food.platformmsgmanagement.port.inbound.AlimentUseCase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/comment")
@CrossOrigin("*")
public class CommentController {
    private final AlimentUseCase useCase;

    @Autowired
    public CommentController(AlimentUseCase useCase) {
        this.useCase = useCase;
    }

    @GetMapping("/getTest/{alimentId}")
    public String getTest(@PathVariable String alimentId) {
        return "test is ok" + alimentId;
    }

    @GetMapping("/getAll/{alimentId}")
    public List<CommentDTO> getAllComment(@PathVariable String alimentId) {
        return useCase.getAllComment(alimentId);
    }

    @GetMapping("/getNum/{alimentId}/{number}")
    public List<CommentDTO> getNumComment(@PathVariable String alimentId, @PathVariable int number) {
        return useCase.getNumComment(alimentId, number);
    }

    @PostMapping("/addComment/{alimentId}/{userName}/{mainText}")
    public String addComment(@PathVariable String alimentId, @PathVariable String userName, @PathVariable String mainText) {
        useCase.addComment(alimentId, userName, mainText);
        return "评论成功";
    }

    @PostMapping("/delete/{id}")
    public boolean deleteComment(@PathVariable String id) {
        return useCase.deleteComment(id);
    }
}
